package com.framework.modules.dataview.controller;

import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;
import com.framework.common.validator.ValidatorUtils;
import com.framework.modules.dataview.entity.ViewUserPostsListEntity;
import com.framework.modules.dataview.service.ViewUserPostsListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * VIEW
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-24 12:44:30
 */
@RestController
@RequestMapping("dataview/viewuserpostslist")
@Api(tags = "ViewUserPostsListController")
public class ViewUserPostsListController {
    @Autowired
    private ViewUserPostsListService viewUserPostsListService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dataview:viewuserpostslist:list")
        @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = viewUserPostsListService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{nickname}")
    @RequiresPermissions("dataview:viewuserpostslist:info")
        @ApiOperation("info")
    public R info(@PathVariable("nickname") String nickname){
        ViewUserPostsListEntity viewUserPostsList = viewUserPostsListService.selectById(nickname);

        return R.ok().put("viewUserPostsList", viewUserPostsList);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        @ApiOperation("save")
    public R save(@RequestBody ViewUserPostsListEntity viewUserPostsList){
        viewUserPostsListService.insert(viewUserPostsList);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        @ApiOperation("update")
    public R update(@RequestBody ViewUserPostsListEntity viewUserPostsList){
        ValidatorUtils.validateEntity(viewUserPostsList);
        viewUserPostsListService.updateAllColumnById(viewUserPostsList);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dataview:viewuserpostslist:delete")
        @ApiOperation("delete")
    public R delete(@RequestBody String[] ids){
        viewUserPostsListService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
